<?php
    namespace yaliSDK\utils;

    class Http {
        public static function http_request($url,$params,$is_no_response=false){
            $curl = curl_init();
            curl_setopt_array($curl, [
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => "",
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => $is_no_response?1:30,
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => "POST",
                CURLOPT_POST => true,
                CURLOPT_HTTPHEADER => ["cache-control: no-cache","content-type: application/json"],
                CURLOPT_POSTFIELDS => json_encode($params),
            ]);
            $response = curl_exec($curl);
            if($is_no_response){
                return true;
            }
            $error = curl_error($curl);
            curl_close($curl);
            if ($error) {
                return $error;
            }else{
                return $response;
            }
        }
    }